<!DOCTYPE html>
<html lang="zh-CN">
<head>
 
<#include "bases/global_style.ftl">
<#include "bases/global_js.ftl">
<#include "bases/combo.ftl">
 
    <script>
        var curent_page=${currentpage};
 
   
        var dataform;
        jQuery(document).ready(function()
        {
            var optInit = getOptionsFromForm();
            $("#Pagination").pagination(${totalRecord}, optInit);
            App.init();
            dataform=$("#dataform").validate({
            });
        });
 
        function doTableSort(ID)
        {
            $("#postsortfield").val(ID);
            $("#currentpage").val(0);
            $("#searchform").submit();
        }
        
        
        function addEntity() 
        {
      	    
        	    dataform.form();
        	    if(dataform.valid()){
	                var a ;
	                var nowtime = new Date();
	                var strtemp = ""+nowtime.getHours()+nowtime.getMinutes()+nowtime.getSeconds()+nowtime.getMilliseconds();
	                a=strtemp;

	                $("#loading").showLoading(); 
	        		$.ajax({  
		      		      type : "POST",  
		      		      url :  "${base}/add_property_company/" + a+"?"+$("#dataform").serialize(),
		      		      dataType : "json",  
		      		      cache : false,  
		      		      async : false,  
		      		      success : function(data) {  
		      		       	    $('#loading').hideLoading();
			      		        if(data ==1) {
			      		        	jAlert("添加成功！");
		                            window.location.reload();
		                        }
		                        else if(data ==-1)
		                        	jAlert("未知错误！");
		      		      }  
	      		    }); 
	                
        	    }

             

        }
        function showAddDiv(){
        	
        	 $("#poppic").attr("class","fa fa-plus");
    		 $("#popname").html("新增产权公司");
    		 $("#dataform #name").attr("data-rule-remote","${base}/checkNameUnique?category=PropertyCompany&where=and del=0");
             resetForm();
        	 showPopup();
        }
         
        function showEditDiv(id){
        	
          $("#loading").showLoading(); 
       	  $("#poppic").attr("class","fa fa-plus");
   	 	  $("#popname").html("编辑产权公司");
        
      	  
          $.ajax({  
      	        type : "POST",  
      	        url : CONTEXT+'/get_property_company_by_id?id='+id,  
      	        dataType : "json",  
      	        success : function(data) {  
      	      	    $("#dataform #editId").val(data.id);
      	      	    $("#dataform #name").val(data.name);
      	            $("#dataform #contactsNo").val(data.contactsNo);
      	            $("#dataform #contacts").val(data.contacts);
      	            $("#dataform #name").attr("data-rule-remote","${base}/checkNameUnique?category=PropertyCompany&where=and del=0 and id!="+data.id);
      	            $('#loading').hideLoading();
		      	    showPopup();
      	        
      	        }  
      	    }); 
        	
        }
        
        function  updateEntity(){
        	
	    	
	   	     dataform.form();
		     if(dataform.valid()){
		   	    	 $("#loading").showLoading(); 
		             $.ajax({  
		       	        type : "POST",  
		       	        url : CONTEXT+'/edit_property_company',  
		       	        data:$("#dataform").serialize(),
		       	        dataType : "json",  
		       	        success : function(data) {  
			       	           $('#loading').hideLoading();
			       	        	if(data.result==true){
			                        window.location.reload();
			       	        	}else{
			       	        		jAlert(data.msg);
			       	        	}
		       	        }  
		       	    }); 
		    }
 

        }
        
 
        function showPopup() 
        {//弹出层
            var backDiv = document.getElementById("backDiv");
            backDiv.style.top = "0%";//设置弹出层距离上边界的距离
            backDiv.style.left = "0%";//设置弹出层距离左边界的距离
            backDiv.style.width = "100%";//设置弹出层的宽度
            backDiv.style.height = "100%";//设置弹出层的高度
            backDiv.style.visibility = "visible";

            var formDiv = document.getElementById("formDiv");
            formDiv.style.top = "10%";//设置弹出层距离上边界的距离
            formDiv.style.left = "30%";//设置弹出层距离左边界的距离
            formDiv.style.width = "40%";//设置弹出层的宽度
            formDiv.style.height = "auto";//设置弹出层的高度
            formDiv.style.visibility = "visible";
        }
        	     
        	     
        function submitFormdata(){
        	
        	 var editId=$("#editId").val();
        	 if (editId != null && editId != "") {
        	     updateEntity();
             }else{
            	 addEntity();
             }
        }
  
 
        function hidePopup() 
        {//关闭层
  
            var formDiv = document.getElementById("formDiv");
            formDiv.style.visibility = "hidden";
   
        	
            var backDiv = document.getElementById("backDiv");
            backDiv.style.visibility = "hidden";
 
            resetForm();
        }
   
       function resetForm(){
    	    $("#dataform input").not(":button, :submit, :reset, :checked").val("");
	       	$("#dataform input[type=reset]").trigger("click");
	        //$("#dataform input[type=checkbox]").eq(0).attr("checked",'true');
	  	    $("#dataform #cityid").empty();
    	    $("#dataform #areaid").empty();
	     	 dataform.resetForm();
       }
    </script>
  
</head>

<body>

<div id="backDiv" onclick="hidePopup()" style="position: absolute;visibility: hidden;position:fixed;overflow: hidden;solid: #000000;background-color: #000000;padding: 1px;z-index: 99;filter:alpha(opacity=50);opacity: 0.5;"></div>

<div id="formDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
    <div class="span12">
        <div class="portlet box green" style="padding: 0px;margin:0px;">
            <div class="portlet-title">
                <div class="caption"><i class="fa fa-edit" id="poppic"></i><span id="popname">新增产权公司</span></div>
                <a href="javascript:allDivHide();" class="remove"></a>
            </div>

            <div class="portlet-body flip-scroll">
                <form id="dataform"   action="<@spring.url 'property_company_manage'></@spring.url>">
                      <table class="table-bordered table-striped table-condensed flip-content">
                        <tbody role="alert" aria-live="polite" aria-relevant="all">
            
                        <tr class="even">
                            <td style="text-align: right;">公司名称<span class="fill-must">*</span></td>
                            <td class="center">
                                   <input   class="m-wrap span8" style="margin-top: 10px" type="text" id="name" name="name" required   placeholder="请输入公司名称" data-msg-remote="名称已存在" onkeyup="dataform.form();"/>
                            </td>
                        </tr>
   
                        <tr class="odd">
                            <td style="text-align: right;">联系人<span class="fill-must">*</span></td>
                            <td class="even">
                                   <input class="m-wrap span8" style="margin-top: 10px" type="text" id="contacts" name="contacts" required  placeholder="请输入联系人" />
                            </td>
                        </tr>
          
 
                    
                        <tr class="even">
                             <td style="text-align: right;">联系人电话<span class="fill-must">*</span></td>
                            <td class="even">
                                   <input class="m-wrap span8" style="margin-top: 10px" type="text" id="contactsNo" name="contactsNo"   required  required data-rule-mobile="true" data-msg-mobile="请输入正确电话格式"  placeholder="请输入联系人电话" />
                            </td>
                        </tr>
             
                        </tbody>
                    </table>
                    </br>
                    <div class="controls controls-row" style="text-align: right;">
                        <input   type="hidden" id="editId" name="id" />
                        <input type="button" value="提交"  class="btn green" onclick="submitFormdata()"/>
                        <input type="button" value="取消"   class="btn green" onclick="hidePopup()" />
                        <input type="reset"  style="display: none" > 
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

 

<div class="page-container row-fluid">

<#include "bases/sidebar.ftl">
<#include "bases/navhead.ftl">

    <div class="page-content secMenu-content" id="loading">
     
        <div class="container-fluid">
 
            <div class="row-fluid">
                <div class="span12">
                    <div class="portlet box green">
                        <div class="portlet-title">
                            <div class="caption"><i class="fa fa-cogs"></i>产权公司列表</div>
                            <div class="tools">
                                <a href="javascript:window.location.reload()" class="reload"></a>
                            </div>
                        </div>
                        <div class="portlet-body flip-scroll">
                            <form id="searchform" action="${base}/property_company_manage" method="POST">
                               
                                <div class="controls controls-row">

                                    <input  type="hidden" id="currentpage" name="page" value="0" />
                                    <input  type="hidden" id="postsortfield" name="sortfield" value="<#if sortfield??>${sortfield}</#if>" />
                             
                                </div>
                                <div class="controls controls-row" style="margin-top: 20px">
                                    <button id="sample_editable_1_new" type="button" class="btn green" onclick="showAddDiv()"><i class="fa fa-plus"></i>增加产权公司</button>
 
                                </div>
                                <table  class="table table-bordered table-hover table-striped table-condensed list-table">
                                    <thead class="flip-content">
                                    <tr>
								          <th style="text-align: center;">公司名称</th>
								          <th style="text-align: center;">联系人</th>
								          <th style="text-align: center;" onclick="javascript:doTableSort('contactsNo')">联系人电话</th>
								          <th style="text-align: center;width: 200px">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <#list property_company_list as pcl>
                                    <tr>
                                        <td style="text-align: center;"><#if pcl.getName()??>${pcl.getName()}</#if></td>
                                        <td style="text-align: center;"><#if pcl.getContacts()??>${pcl.getContacts()}</#if></td>
                                        <td style="text-align: center;"><#if pcl.getContactsNo()??>${pcl.getContactsNo()}</#if></td>
                                        <td style="text-align: center;">
                                         
                                         
                                         	<a id="editButton" onclick="showEditDiv('${pcl.getId()}');">编辑</a>
                                      
                                        </td>
                                    </tr>
                                    </#list>
                                    </tbody>
                                </table>
                                <div class="controls controls-row">
                                    <div id="Pagination" class="pagination"></div>
                               </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
  </div>
 
</body>
</html>

 
